package br.com.consultsystems.dominio.configuracao;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;

import br.com.consultsystems.dominio.tipos.UsuarioPerfil;

@Entity
@Table(name = "usuario")
@SequenceGenerator(name = "operacao", sequenceName = "operacao")
@XmlRootElement
public class Usuario implements Serializable {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 4829272729557740896L;

	@Id
	@Column(name = "id", nullable = false, insertable = true, updatable = false)
	@GeneratedValue(generator = "operacao", strategy = GenerationType.SEQUENCE)
	private Long id;
	
	@Column(name = "nome", nullable = false, insertable = true, updatable = true, length = 200)
	private String nome;
	
	@Column(name = "email", nullable = false, insertable = true, updatable = false, unique = true, length = 200)
	private String email;

	@Column(name = "senha", nullable = false, insertable = true, updatable = true, length = 32)
	private String senha;

	@Column(name = "perfil", nullable = false, insertable = true, updatable = true, length = 32)
	@Enumerated(EnumType.STRING)
	private UsuarioPerfil perfil;
	
	@Transient
	private String session;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public String getSession() {
		return session;
	}

	public void setSession(String session) {
		this.session = session;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public UsuarioPerfil getPerfil() {
		return perfil;
	}

	public void setPerfil(UsuarioPerfil perfil) {
		this.perfil = perfil;
	}


	@Override
	public String toString() {
		return "Usuario [id=" + id + ", nome=" + nome + ", email=" + email
				+ ", senha=" + senha + ", perfil=" + perfil + ", session="
				+ session + "]";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Usuario other = (Usuario) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
